package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type ResourceDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewResourceDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResourceDetailLogic {
	return &ResourceDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 资源-详情
func (l *ResourceDetailLogic) ResourceDetail(in *pd.UmsResourceDetailReq) (*pd.UmsResourceDetailResp, error) {
	d, err := l.svcCtx.UmsResourceModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}
	var resp pd.UmsResource
	copier.Copy(&resp, d)
	return &pd.UmsResourceDetailResp{D: &resp}, nil
}
